/**
 * Represents the context passed to a plugin's activation function.
 */
export interface PluginContext {
  subscriptions: { dispose(): any }[];
}

/**
 * Defines the structure of the plugin's manifest file (plugin.json).
 */
export interface PluginManifest {
  name: string;
  displayName: string;
  version: string;
  description: string;
  author: string;
  main: string; // Entry point for frontend plugin
  backend?: string; // Entry point for backend plugin
  activationEvents: ('onCommand' | 'onLanguage' | 'onStartup')[];
  contributes?: {
    commands?: {
      command: string;
      title: string;
    }[];
    menus?: {
      [key: string]: {
        command: string;
        when?: string; // Condition to show menu item
      }[];
    };
    views?: {
      [key:string]: {
        id: string;
        name: string;
        icon: string;
      }[];
    }
  };
}

/**
 * The API exposed to all plugins.
 */
export interface PluginAPI {
  commands: {
    registerCommand(command: string, callback: (...args: any[]) => any): { dispose: () => void };
    executeCommand<T>(command: string, ...args: any[]): Promise<T>;
  };
  window: {
    showInformationMessage(message: string): void;
    // Add more window-related APIs here
  };
  workspace: {
    rootPath: string | undefined;
    // Add more workspace-related APIs here
  };
  // For communication with backend plugins
  rpc: {
    invoke<T>(command: string, params: any): Promise<T>;
  };
  // Editor API
  editor: {
    registerAction(action: {
      id: string;
      label: string;
      keybindings?: number[];
      precondition?: string;
      contextMenuGroupId?: string;
      contextMenuOrder?: number;
      run: (editor: any) => void | Promise<void>;
    }): { dispose(): void };
  };

  // Language providers API
  languages: {
    registerCompletionProvider(languageId: string, provider: any): { dispose(): void };
    // 新增：内联补全提供者注册
    registerInlineCompletionsProvider(languageId: string, provider: any): { dispose(): void };
    registerHoverProvider(languageId: string, provider: any): { dispose(): void };
    registerCodeActionProvider(languageId: string, provider: any): { dispose(): void };
    registerDocumentFormattingEditProvider(languageId: string, provider: any): { dispose(): void };
    registerDocumentRangeFormattingEditProvider(languageId: string, provider: any): { dispose(): void };
    registerDefinitionProvider(languageId: string, provider: any): { dispose(): void };
    registerReferenceProvider(languageId: string, provider: any): { dispose(): void };
    registerRenameProvider(languageId: string, provider: any): { dispose(): void };
    registerLanguage(config: {
      id: string;
      monarchTokensProvider?: any;
      languageConfiguration?: any;
    }): void;
  };

  // Theme API
  themes: {
    registerTheme(theme: any): void;
    setTheme(themeId: string): void;
  };
}